<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <el-row>
        <el-col :span="6">
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格数据 -->
      <el-table :data="orderList" border stripe style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <!-- 渲染成自己想要的的样子 -->
          <template v-slot="scope">
            <el-tag type="warning" v-if="scope.row.pay_status === '0'"
              >未付款</el-tag
            >
            <el-tag type="success" v-else>付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="180">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <!-- 把下单时间渲染成自己想要的样子  -->
          <template v-slot="scope">
            {{ scope.row.create_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template >
            <el-button
              type="primary"
              size="small"
              icon="el-icon-edit"
              @click="showAddressDialogVisible"
            ></el-button>
            <el-button
            @click="showStreamDialogVisible"
              type="success"
              size="small"
              icon="el-icon-location"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 显示修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="addressDialogVisible"
      width="30%"
      @close="addressDialogVisibleClosed"
    >
      <el-form
        ref="addressFormRef"
        :model="addressForm"
        :rules="addressFormRules"
        label-width="90px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="selectCity"
            :options="citydata"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="具体地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <el-button @click="addressDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="addressDialogVisible = false"
        >确 定</el-button
      >
    </el-dialog>
    <!-- 显示物流 -->
    <el-dialog
      title="提示"
      :visible.sync="streamDialogVisible"
      width="30%"
    >
      <span>物流信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="streamDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="streamDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import citydata from '@/components/citydata'
export default {
  data () {
    return {
      // 请求参数
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      // 获取的订单列表
      orderList: [],
      // 总条数
      total: 1,
      // 显示修改地址的对话框
      addressDialogVisible: false,
      // 修改地址的数据
      addressForm: {
        address1: '',
        address2: ''
      },
      // 修改地址的规则
      addressFormRules: {
        address1: [
          {
            required: true,
            trigger: 'blur',
            message: '请选择省市区'
          }
        ],
        address2: [
          {
            required: true,
            trigger: 'blur',
            message: '写入具体地址'
          }
        ]
      },
      citydata,
      // 选中的城市
      selectCity: [],
      streamDialogVisible: false
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // 获取订单列表
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('请求失败')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 当每页个数发生改变
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    // 当前页码改变
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    },
    showAddressDialogVisible () {
      this.addressDialogVisible = true
    },
    // 选择的城市
    handleChange () {},
    // 关闭修改地址对话框
    addressDialogVisibleClosed () {
      this.$refs.addressFormRef.resetFields()
    },
    // 显示物流的对话框
    async  showStreamDialogVisible () {
      this.streamDialogVisible = true
    }
  }
}
</script>
<style  scoped>
.el-cascader {
  width: 100%;
}
</style>>
